import java.util.HashSet;
import java.util.Random;
import java.util.Scanner;
import java.util.Set;

public class test3 {

    public static void main(String[] args) {
        int[] numOfProblems = {5, 6, 7, 23, 24, 25, 59, 60, 61, 119, 120};

        for (int num : numOfProblems) {
            String[] problems = generateArithmeticProblems(num);

            // 打印题目
            System.out.println("共 " + num + " 道算术题：");
            printProblems(problems);}

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入两个数，用空格分隔：");

        int num1 = Integer.parseInt(scanner.next());
        int num2 = Integer.parseInt(scanner.next());

        // 加法验证
        try {
            if (num1 >= 0 && num1 <= 100 && num2 >= 0 && num2 <= 100 && num1+num2 <= 100) {
                int additionResult = num1 + num2;
                System.out.println("加法结果正确！实际结果为：" + additionResult);
            }else if(num1+num2 >100){
                System.out.println("错误，加法接错超过100！！！！");
            }
            else {
                System.out.println("请输入 0 到 100 之间的整数进行加法验证！");
            }
        } catch (NumberFormatException e) {
            System.out.println("输入错误，请输入整数进行加法验证！");
        }

        // 减法验证
        Scanner scanner1 = new Scanner(System.in);
        System.out.println("请输入两个数，用空格分隔：");

        int num3 = Integer.parseInt(scanner1.next());
        int num4 = Integer.parseInt(scanner1.next());
        try {
            if (num3 >= 0 && num3 <= 100 && num4 >= 0 && num4 <= 100 && num3-num4>=0) {
                int subtractionResult = num1 - num2;
                System.out.println("减法结果正确！实际结果为：" + subtractionResult);
            }else if(num3-num4<0){
                System.out.println("错误，减法结果为负数！！！");
            }
            else {
                System.out.println("请输入 0 到 100 之间的整数进行减法验证！");
            }
        } catch (NumberFormatException e) {
            System.out.println("输入错误，请输入整数进行减法验证！");
        } finally {
            scanner.close();
        }
    }

    public static String[] generateArithmeticProblems(int numOfProblems) {
        Set<String> problemSet = new HashSet<>();
        Random random = new Random();

        while (problemSet.size() < numOfProblems) {
            int a = random.nextInt(101); // 0 - 100
            int b = random.nextInt(101); // 0 - 100

            if (a + b <= 100 && a >= b) {
                String operator = random.nextBoolean()? "+" : "-";
                int result = operator.equals("+")? a + b : a - b;
                String problem = a + " " + operator + " " + b + " = " + result;
                problemSet.add(problem);
            }
        }

        return problemSet.toArray(new String[0]);
    }

    public static boolean isValidInput(int num1, int num2) {
        return num1 >= 0 && num1 <= 100 && num2 >= 0 && num2 <= 100 && (num1 + num2 <= 100 || num1 - num2 >= 0);
    }

    public static boolean checkAnswer(String[] problems, int num1, int num2, int result) {
        String operator = num1 >= num2? "+" : "-";
        String inputProblem = num1 + " " + operator + " " + num2 + " = " + result;

        for (String problem : problems) {
            if (problem.equals(inputProblem)) {
                return true;
            }
        }

        return false;
    }

    // 打印题目
    public static void printProblems(String[] problems) {
        for (int i = 0; i < problems.length; i++) {
            if (i > 0 && i % 6 == 0) {
                System.out.println();
            }
            System.out.print(problems[i] + "\t");
        }
        System.out.println();
    }
}
